const {commentSet} = require("./commentSet");
const {getCommentList} = require('./api')

const createjob = (socket) => {
    const CronJob = require('cron').CronJob;
    const job = new CronJob(
        '0/10 * * * * *',
        async function () {
            const data = await getCommentList(1);
            const canSendDataList = [];
            console.log(data);
            for (const reply of data.dataList) {
                if (!commentSet[reply.rpid]){
                    canSendDataList.push(reply);
                    commentSet[reply.rpid] = reply;
                }
            }
            socket.broadcast.emit('sendDate',{
                ...data,
                dataList: canSendDataList
            });
        },
        null,
        true,
        'America/Los_Angeles'
    );

    job.start()
}

module.exports = {
    createjob
}
